<?php

namespace App\Http\Handlers;

use EasyDingTalk\Application;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;

class DingTalkHandler
{
    /**
     * @param \EasyDingTalk\Application $app
     */
    public function __construct($app)
    {
    }

    /**
     * @param  array $payload
     *
     * @return void
     */
    public function __invoke($payload)
    {
        if (isset($payload['EventType'])) {
            Log::info($payload['EventType']);
            $method = Str::camel($payload['EventType']);
            if (method_exists($this, $method)) {
                $this->$method($payload);
            } else {
                Log::info("EventType 对应的方法不存在");
            }
        } else {
            Log::info("错误的EventType");
        }
    }

    /**
     * 通讯录用户增加
     */
    public function userAddOrg($payload)
    {
        Log::info(json_encode($payload));
    }

    /**
     * 通讯录用户更改
     */
    public function userModifyOrg($payload)
    {
        Log::info(json_encode($payload));
    }

    /**
     * 通讯录用户离职
     */
    public function userLeaveOrg($payload)
    {
        Log::info(json_encode($payload));
    }

    /**
     * 加入企业后用户激活
     */
    public function userActiveOrg($payload)
    {
        Log::info(json_encode($payload));
    }

    /**
     * 通讯录用户被设为管理员
     */
    public function orgAdminAdd($payload)
    {
        Log::info(json_encode($payload));
    }

    /**
     * 通讯录用户被取消设置管理员
     */
    public function orgAdminRemove($payload)
    {
        Log::info(json_encode($payload));
    }

    /**
     * 通讯录企业部门创建
     */
    public function orgDeptCreate($payload)
    {
        Log::info(json_encode($payload));
    }

    /**
     * 通讯录企业部门修改
     */
    public function orgDeptModify($payload)
    {
        Log::info(json_encode($payload));
    }

    /**
     * 通讯录企业部门删除
     */
    public function orgDeptRemove($payload)
    {
        Log::info(json_encode($payload));
    }

    /**
     * 企业被解散
     */
    public function orgRemove($payload)
    {
        Log::info(json_encode($payload));
    }

    /**
     * 企业信息发生变更
     */
    public function orgChange($payload)
    {
        Log::info(json_encode($payload));
    }

    /**
     * 员工角色信息发生变更
     */
    public function labelUserChange($payload) 
    {
        Log::info(json_encode($payload));
    }

    /**
     * 增加角色或者角色组
     */
    public function labelConfAdd($payload) 
    {
        Log::info(json_encode($payload));
    }

    /**
     * 删除角色或者角色组
     */
    public function labelConfDel($payload) 
    {
        Log::info(json_encode($payload));
    }

    /**
     * 修改角色或者角色组
     */
    public function labelConfModify($payload) 
    {
        Log::info(json_encode($payload));
    }
}
